package com.qst.unitetest;

import com.qst.bean.wjrBean;
import com.qst.dao.wjrBeanMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class testDriver {
    @Test
    public void  test01(){
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            // 创建了mybatis的sqlSessionFactory工厂类:读取mybatis.xml配置文件，使用该配置文件中的参数信息，用于创建SqlSession对象
            SqlSessionFactory sqlSessionFactory =
                    new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            // 从mybatis的sqlsession对象中获取dao层的接口的实例对象
            wjrBeanMapper wjrBeanMapper = session.getMapper(wjrBeanMapper.class);
            // 调用dao层接口的方法进行数据库操作
            wjrBean wjrBean = wjrBeanMapper.selectByPrimaryKey(3l);
            System.out.println("mybatis查询结果：");
            System.out.println(wjrBean);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



